/*
 * table_CppFileNestInfo_t.c
 *
 *  Created on: 2012/03/31
 *      Author: guanxiaoying
 */
#include "../../parser/coredef.h"

/*KIND_CURRENTINFO	*/
typedef struct _CURRENTINFO
{
	HFILE		hFile;											/* 2 */
	CHAR		szCurrFileName[OS_FULLPATH+4];		/* 3 */
	S4		logicLine;		/* 4 */
	S4		physicalLine;	/* 5 */
	AST		astFileIndex;			/* 7 */
	AST		astLineNumInfo;		/* 8 */
	AST		astLocation;			/* 9 */
} FILENESTINFO, *PFILENESTINFO;


#define TableSize  (sizeof(FILENESTINFO))
#define TableType  PFILENESTINFO
#define stTable stCppFileNestManager.memoryBlocks
#define maxTable stCppFileNestManager.maxRecordNum
#define  maxNumPerBlk  (stCppFileNestManager.astMaxNum_Block)

/* private field */

static TABLEMANAGER stCppFileNestManager = {
//		U4                  usIdx;
		0,
//		PSZ				    con_pszName;    constant
		__FILE__,
//		U2					con_usSize;		constant
		TableSize,
//		U2					block_num;	　　　　　　　Reset clear  際　要
		0,
//		S4					astMaxNum_Block;     １回設定のみ
		0,
//		S4					astTabNum_LastPage; 　　　　Reset clear  際　要
		0,
//		S4					astMaxNum_LastPage;     Reset clear  際　要
		0,
//		U4					ulMaxByte;	　　　　　　　　　　クリアしない
		0,
//		U4					con_minPageSize;　　　　　　　　　　constant
		0
};
static VOID resetListener( U4  procid, U2 index )
{
	if( procid == stCppFileNestManager.u4Idx )
	{
		if( index > 0 && index < MAX_VOLUMN_OF_TABLE )
		{
			stTable[ index-1] = NULL;
		}
	}
}
static TableType core_getTable( AST index )
{
	TableType temp = (TableType)Check_Com( &stCppFileNestManager, resetListener, index );
	if( temp != NULL ){ return &temp[index%maxNumPerBlk]; } return NULL;
}
static BOOL ClearTable( VOID )
{
	return Clear_Com( &stCppFileNestManager );
}
static BOOL ResetTable( VOID )
{
	return Reset_Com( &stCppFileNestManager );
}
static BOOL AllocTable( AST astReqArg )
{
	return AllocTable_Com( &stCppFileNestManager, astReqArg, resetListener );
}
static AST getMaxLineNum( VOID )
{
	return maxTable;
}
/* give up the way that defining get/set function pointer in the struct,
 * because of memory volume.
 */
//ACCESS_STR_FIELD filePath;
static CHAR*   Get_Path( AST index )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return "";
	}
	return pTbl->szCurrFileName;
}
/* STR_FILENAME   set method */
static AST   Set_Path( AST index, CHAR * pszStr  )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		assert_index( maxFileIndex, index, (S4)pszStr );
		return 0;
	}
	if( str_length( pszStr ) >= OS_FULLPATH )
	{
		strncpy( pTbl->szCurrFileName, pszStr, OS_FULLPATH-1 );
		pTbl->szCurrFileName[OS_FULLPATH-1] = '\0';
	}
	else if ( str_length( pszStr ) > 0 )
	{
		strcpy( pTbl->szCurrFileName, pszStr );
		pTbl->szCurrFileName[strlen(pszStr)] = '\0';
	}
	else
	{
		pTbl->szCurrFileName[0] = '\0';
	}
	return index;
}

//ACCESS_S4_FIELD  fileHandle;
static S4   getFileHandle( AST index )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->hFile;
}
/* new   set method */
static S4   setFileHandle( AST index, S4 value )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->hFile = value;
}
//ACCESS_S4_FIELD  logicLine;
static S4   getLogicLine( AST index )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->logicLine;
}
/* new   set method */
static S4   setLogicLine( AST index, S4 value )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->logicLine = value;
}
//ACCESS_S4_FIELD  physicalLine;
static S4   getPhysicalLine( AST index )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->physicalLine;
}
/* new   set method */
static S4   setPhysicalLine( AST index, S4 value )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->physicalLine = value;
}
//ACCESS_IDX_FIELD fileIndex;
static AST   getFileIndex( AST index )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->astFileIndex;
}
/* new   set method */
static S4   setFileIndex( AST index, S4 value )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->astFileIndex = value;
}
//ACCESS_IDX_FIELD lineInfo;
static AST   getLineInfo( AST index )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->astFileIndex;
}
/* new   set method */
static S4   setLineInfo( AST index, S4 value )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->astFileIndex = value;
}
//ACCESS_IDX_FIELD location;
static AST   getLocation( AST index )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->astFileIndex;
}
/* new   set method */
static S4   setLocation( AST index, S4 value )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->astFileIndex = value;
}
const NESTFILEINFO stCppNestFileInfoAccess = {
//		BOOL (*clear)( VOID );
		ClearTable,
//		BOOL (*reset)( VOID );
		ResetTable,
//		BOOL (*alloc)( AST );
		AllocTable,
//		AST  (*getMax)( VOID );
		getMaxLineNum,
//		ACCESS_STR_FIELD filePath;
		{
				Get_Path,
				Set_Path
		},
//		ACCESS_S4_FIELD  fileHandle;
		{
				getFileHandle,
				setFileHandle
		},
//		ACCESS_S4_FIELD  logicLine;
		{
				getLogicLine,
				setLogicLine
		},
//		ACCESS_S4_FIELD  physicalLine;
		{
				getPhysicalLine,
				setPhysicalLine
		},
//		ACCESS_IDX_FIELD fileIndex;
		{
				getFileIndex,
				setFileIndex
		},
//		ACCESS_IDX_FIELD lineInfo;
		{
				getLineInfo,
				setLineInfo
		},
//		ACCESS_IDX_FIELD location;
		{
				getLocation,
				setLocation
		}
};
